<?php

class Admin_Table_Auction_ExchangeFile extends Apk_Db_Table {

    protected $_name = 'exchange_file';
    protected $_primary = 'ID';
    public $_ERROR = "";

    public function GetError() {
        return $this->_ERROR;
    }

    public function GetDataRow($params = array()){
    	$data = array();
    	$sel = $this->getAdapter()->select()->from($this->_name);
    	
    	if (!empty($params)) {
    		foreach ($params as $k => $v){
    			switch ($k) {
    				default:
    					if(intval($v)>0) $sel->where("id_lot = ?", intval($v));
    					break;
    			}
    		}
    	}
    	
    	$data = $this->getList($sel)->toArray();
    	if (!empty($data)) $data = $data[0];

        return $data;
    }
    
    public function insert(array $data, $user_id) {
        $data['add_user_id'] = $user_id;
        $date['add_date'] = new Zend_Db_Expr("now()");
        try {
            parent::insert($data);
            return $this->getAdapter()->lastInsertId($this->_name);
        } catch (Exception $e) {
            return false;
        }
    }

    public function update(array $data, $id) {
        try {
            $data['modify_user_id'] = $user_id;
            return parent::update($data, 'id = ' . $id);
        } catch (Exception $e) {
            return false;
        }
    }

}
